#!/usr/bin/env python
# -*- coding:utf-8 -*-

import bpy
import sys
import os

# sys.path.append(r'D:\Develop\GitRepos\BIM\blender\2018\03')

# Function for entering Edit Mode with no vertices selected,
# or entering Object Mode with no additional processes
def mode(mode_name):
    bpy.ops.object.mode_set(mode=mode_name)
    if mode_name == "EDIT":
        bpy.ops.mesh.select_all(action="DESELECT")

def mode2(mode_name):
    bpy.ops.object.mode_set(mode=mode_name)
    if mode_name == "EDIT":
        bpy.ops.mesh.select_all(action="DESELECT")

def active(objName):
    bpy.context.scene.objects.active = bpy.data.objects[objName]

def select(objName):
    bpy.ops.object.select_all(action = 'DESELECT')
    bpy.data.objects[objName].select = True

class sel:
    def translate(v):
        bpy.ops.transform.translate(value = v, constraint_axis = (True, True, True))

    def scale(v):
        bpy.ops.transform.resize(value = v, constraint_axis = (True, True, True))

    def rotate_x(v):
        bpy.ops.transform.rotate(value = v, axis = (1, 0, 0))

    def rotate_y(v):
        bpy.ops.transform.rotate(value = v, axis = (0, 1, 0))

    def rotate_z(v):
        bpy.ops.transform.rotate(value = v, axis = (0, 0, 1))

class act:
    def location(v):
        bpy.context.object.location = v

    def scale(v):
        bpy.context.object.scale = v

    def rotation(v):
        bpy.context.object.rotation_euler = v

    def rename(objName):
        bpy.context.object.name = objName

class spec:
    """Function Class for operating on SPECIFIED objects"""
    # Declarative
    def scale(objName, v):
        bpy.data.objects[objName].scale = v

    # Declarative
    def location(objName, v):
        bpy.data.objects[objName].location = v

    # Declarative
    def rotation(objName, v):
        bpy.data.objects[objName].rotation_euler = v

class create:
    """Function Class for CREATING Objects"""
    def cube(objName):
        bpy.ops.mesh.primitive_cube_add(radius=0.5, location=(0, 0, 0))
        act.rename(objName)

    def sphere(objName):
        bpy.ops.mesh.primitive_uv_sphere_add(size=0.5, location=(0, 0, 0))
        act.rename(objName)

    def cone(objName):
        bpy.ops.mesh.primitive_cone_add(radius1=0.5, location=(0, 0, 0))
        act.rename(objName)

# Delete an object by name
def delete(objName):
    select(objName)
    bpy.ops.object.delete(use_global=False)

# Delete all objects
def delete_all():
    if(len(bpy.data.objects) != 0):
        bpy.ops.object.select_all(action='SELECT')
        bpy.ops.object.delete(use_global=False)


if __name__ == "__main__":
    # Create a cube
    create.cube('PerfectCube')
    # Differential transformations combine
    sel.translate((0, 1, 2))
    sel.scale((1, 1, 2))
    sel.scale((0.5, 1, 1))
    sel.rotate_x(3.1415 / 8)
    sel.rotate_x(3.1415 / 7)
    sel.rotate_z(3.1415 / 3)
    # Create a cone
    create.cone('PointyCone')
    # Declarative transformations overwrite
    act.location((-2, -2, 0))
    spec.scale('PointyCone', (1.5, 2.5, 2))
    # Create a Sphere
    create.sphere('SmoothSphere')
    # Declarative transformations overwrite
    spec.location('SmoothSphere', (2, 0, 0))
    act.rotation((0, 0, 3.1415 / 3))
    act.scale((1, 3, 1))

    print(__file__)
    print(os.path.abspath(__file__))
    print(sys.path)